window.onload = function () {
    var xhr = new XMLHttpRequest()
    xhr.open('get', "/studio/album/list.json")
    xhr.onload = function () {
        var data = JSON.parse(this.responseText)
        var tbody = document.querySelector('tbody')
        for (var i in data) {
            var albumInfo = data[i]
            var bindHref = `/studio/album/albumInfo.html?aid=${albumInfo.aid}`
            var op, opDo, state
            if (albumInfo.state === 2) {
                state = "已发布"
                op = "下线"
                opDo = `/studio/album/withdraw.do?aid=${albumInfo.aid}`
            } else {
                state = "未发布"
                op = "发布"
                opDo = `/studio/album/publish.do?aid=${albumInfo.aid}`
            }
            var html = `<tr><td>${albumInfo.aid}</td><td>${albumInfo.title}</td><td><img src="${albumInfo.cover}"></td><td>${state}</td><td><a href="${bindHref}">查看专辑</a></td><td><a href="${opDo}">${op}</a></td></tr>`
            tbody.innerHTML += html
        }
    }
    xhr.send()
}